﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

namespace NeroConnect.Network
{
	[Serializable]
	class WebExceptionImpl : WebException
	{
		System.Net.WebException _exception;
		HttpResponse _response;

		protected WebExceptionImpl(SerializationInfo info, StreamingContext context):base(info, context)
		{
		}

		public WebExceptionImpl(System.Net.HttpListenerException ex)
			: base(ex.Message, ex)
		{
			_exception = new System.Net.WebException(ex.Message, System.Net.WebExceptionStatus.RequestCanceled);
		}

		public WebExceptionImpl(System.Net.WebException ex) : base(ex.Message, ex.InnerException)
		{
			_exception = ex;
			if (ex.Response != null)
				_response = new HttpResponse(ex.Response as System.Net.HttpWebResponse);
		}

        public WebExceptionImpl(System.IO.IOException ex)
            : base(ex.Message, ex)
        {
            
        }

		public override IResponse Response
		{
			get { return _response; }
		}

        public override System.Net.WebExceptionStatus Status
        {
            get
            {
                if (_exception != null)
                    return _exception.Status;

                return System.Net.WebExceptionStatus.UnknownError;
            }
        }		
	}
}
